/* GUI CONVERTED from mrllupa.p (converter v1.75) Thu Aug 24 13:30:41 2000 */
/* mrllupa.p -- Validate that components/sources have in_mstr records   */
/* Copyright 1986-2004 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.10.1.4.3.1 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.3     LAST EDIT: 06/14/96      BY: *G1XP* evan bishop    */
/* REVISION: 8.5      LAST MODIFIED: 11/10/97   BY: *J1PS* Felcy D'Souza  */
/* REVISION: 8.6E     LAST MODIFIED: 04/23/98   BY: *J23R* Santhosh Nair  */
/* REVISION: 8.6E     LAST MODIFIED: 07/06/98   BY: *G2RJ* Niranjan R.    */
/* REVISION: 8.6E     LAST MODIFIED: 09/01/98   BY: *J2YC* Santhosh Nair  */
/* REVISION: 9.0      LAST MODIFIED: 04/10/00   BY: *M0LL* Kirti Desai    */
/* REVISION: 9.0      LAST MODIFIED: 08/10/00   BY: *M0R6* Rajesh Thomas  */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown     */
/* $Revision: 1.10.1.4.3.1 $    BY: Nishit V              DATE: 03/02/04  ECO: *P1RL*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
     /* This subroutine validates that in_mstr records with unresolved
     low level codes (equal to 99999) have components (for manufactured
     items) or sources of supply (DRP items) that have valid in_mstr
     records. If there are components or sources of supply that don't
     have in_mstr records they will be created.  The goal is to convert
     all in_mstr records with low_level = 99999 to be low_level = 88888
     (which means there is a valid chain of in_mstr records below them).
     */
/* GLOBAL SHARED VARIABLES INCLUDE FILE */
         {mfglobal.i}
         define variable bomcode as character extent 100 no-undo.
         define variable network as character no-undo.
         define variable lvl as integer no-undo.
         define variable init_level as integer no-undo.
         define variable ps_recid as recid extent 100 no-undo.
         define variable in_recid as recid no-undo.
         define variable five_eights as integer initial 88888 no-undo.
         define variable five_nines as integer initial 99999 no-undo.
define variable inrecno      as recid                 no-undo.
define variable comp         as character             no-undo.
define variable null-char    as character             no-undo.
define variable null-integer as integer               no-undo.
/* LOW LEVEL CODE UPDATE */
{gpllupb.i "shared"}
         mainloop:
do while true:
   define query q-inmstr-wkfl
      for inmstr-wkfl.
   open query q-inmstr-wkfl
      for each inmstr-wkfl
               where inmstr-level = five_nines.
            get first q-inmstr-wkfl.

   if not available inmstr-wkfl
   then
      leave.
            do while true:
      if not available inmstr-wkfl
      then
         leave.
               assign
                  bomcode[1]   = inmstr-bom-network
                  network      = inmstr-bom-network
                  pmcode       = inmstr-pmcode
                  site         = inmstr-site
                  inmstr-level = five_eights.
      /* PURCHASED ITEM OR DRP WITH INVALID SOURCE NETWORK */
               if pmcode = "P"
         or (pmcode      = "D"
             and network = "")
               then do:
         for first in_mstr
            fields (in_level in_part in_site)
                     where in_part  = inmstr-part
                     and   in_site  = inmstr-site
            and   in_level = 0
            no-lock:
                     inmstr-level = 0.
         end. /* FOR FIRST in_mstr */

                  get next q-inmstr-wkfl.
                  next.
      end. /* IF pmcode = "P" OR ... */

      /* DRP ITEM WITH NON-BLANK SOURCE NETWORK CODE */
      else
         if pmcode = "D"
         then do:

            part = inmstr-part.
            for each ssd_det
               fields(ssd_end      ssd_network ssd_rec_site
                      ssd_src_site ssd_start)
               where ssd_rec_site =  site
               and   ssd_network  =  network
               and   (ssd_start   <= today
               or     ssd_start   =  ?)
               and   (ssd_end     >= today
               or     ssd_end     =  ?)
               no-lock,
               first si_mstr
                  fields(si_cur_set si_db si_gl_set si_site)
               where si_site = ssd_rec_site
               and   si_db   = global_db
               no-lock:
               if not can-find (first inmstr-wkfl
                                  where inmstr-part = part
                                  and   inmstr-site = ssd_src_site)
               then do:
                  inlevel = ?.
                  for first in_mstr
                     fields (in_level in_part in_site)
                     where in_part = part
                     and   in_site = si_site
                     no-lock:
                        inlevel = in_level.
                  end. /* FOR FIRST in_mstr */
                  if not available in_mstr
                  then do:
                        /* CREATING INVENTORY MASTER RECORD */
                        {gprun.i ""gpincr.p""
                                 "(input yes,
                                   input part,
                                   input ssd_src_site,
                                   input null-char,
                                   input null-char,
                                   input null-char,
                                   input null-integer,
                                   input null-integer,
                                   input null-char,
                                   input no,
                                   input null-char,
                                   input no,
                                   output inrecno)" }
                     if inrecno <> ?
                     then
                           inlevel = five_nines.
                  end. /* IF NOT AVAILABLE in_mstr */

                  if inlevel <> ?
                  then do:
                        /* CREATION OF TEMP-TABLE */
                        {gpllupc.i &part        = part
                                   &site        = ssd_src_site
                                   &level       = inlevel
                                   &pmcode      = pmcode
                                   &bom-network = bom-network
                                   &return-code = return-code}
                     end. /* IF INLEVEL <> ? */
               end. /* IF NOT CAN-FIND(... */
            end. /* FOR EACH ssd_det */
         end. /* IF pmcode = "D" */
         /* MANUFACTURED ITEMS */
            else do:
               lvl = 1.
            for first ps_mstr
               fields (ps_par ps_comp ps_ref ps_start)
               where ps_par = bomcode[lvl]
               use-index ps_parcomp
               no-lock:
            end. /* FOR FIRST ps_mstr */
               psmstr-loop:
               repeat:
               if not available ps_mstr
               then
                  repeat:
                     lvl = lvl - 1.
                     if lvl < 1
                     then
                        leave.
                     for first ps_mstr
                        fields(ps_par ps_comp ps_ref ps_start)
                        where recid(ps_mstr) = ps_recid[lvl]
                        no-lock:
                     end. /* FOR FIRST ps_mstr */
                     if available ps_mstr
                     then do:
                        comp = ps_comp.
                        for first ps_mstr
                           fields(ps_par ps_comp ps_ref ps_start)
                           where ps_par  = bomcode[lvl]
                           and   ps_comp > comp
                           use-index ps_parcomp
                           no-lock:

                        end. /* FOR FIRST ps_mstr */

                     end. /* IF AVAILABLE ps_mstr */

                     if available ps_mstr
                     then
                        leave.
               end. /* IF NOT AVAILABLE ps_mstr */

               if lvl < 1
               then
                  leave.

               if not available ps_mstr
               then
                  leave.
               if not can-find (first inmstr-wkfl where inmstr-part = ps_comp
                                                  and   inmstr-site = site)
                  then do:
                  if can-find (pt_mstr where pt_part = ps_comp)
                  then do:
                        inlevel = ?.
                        for first in_mstr
                        fields (in_level in_part in_site)
                        where in_part = ps_comp
                        and   in_site = site
                        no-lock:

                           inlevel = in_level.
                     end. /* FOR FIRST in_mstr */

                     if not available in_mstr
                     then do:
                           /* CREATING INVENTORY MASTER RECORD */
                           {gprun.i ""gpincr.p""
                                    "(input yes,
                                      input ps_comp,
                                      input site,
                                      input null-char,
                                      input null-char,
                                      input null-char,
                                      input null-integer,
                                      input null-integer,
                                      input null-char,
                                      input no,
                                      input null-char,
                                      input no,
                                      output inrecno)" }
                        if inrecno <> ?
                        then
                              inlevel = five_nines.
                     end. /* IF NOT AVAILABLE in_mstr */

                     if inlevel <> ?
                     then do:
                           /* CREATION OF TEMP-TABLE */
                           {gpllupc.i &part = ps_comp
                                      &site = site
                                      &level = inlevel
                                      &pmcode = pmcode
                                      &bom-network = bom-network
                                      &return-code = return-code}
                        end. /* IF INLEVEL <> ? */
                  end. /* IF CAN-FIND(pt_mstr) */
                     else do:
                     assign
                           ps_recid[lvl] = recid(ps_mstr)
                           lvl           = lvl + 1
                           bomcode[lvl]  = ps_comp.
                     for first ps_mstr
                        fields (ps_par ps_comp ps_ref ps_start)
                        where ps_par = bomcode[lvl]
                        use-index ps_parcomp
                        no-lock:
                     end. /* FOR FIRST ps_mstr */
                        next psmstr-loop.
                  end. /* ELSE DO */
               end. /* IF NOT CAN-FIND(in_mstr) */
                  comp = ps_comp.

                  for first ps_mstr
                  fields(ps_par ps_comp ps_ref ps_start)
                  where ps_par  = bomcode[lvl]
                  and   ps_comp > comp
                  use-index ps_parcomp
                  no-lock:
               end. /* FOR FIRST ps_mstr */

            end. /* psmstr-loop */
         end. /* ELSE DO */

         get next q-inmstr-wkfl.
   end. /* DO WHILE TRUE */

end. /* DO WHILE TRUE */
